/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

/**
 * <p>Project: app2022 - Img4
 * <p>Powered by webrx On 2022-01-21 09:15:37
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Img4 {
    public static void main(String[] args) throws Exception {
        var w = 500;
        var h = 500;
        var t = 2;
        var i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        //颜色对象
        Color c = Color.YELLOW;

        Color y = new Color(255, 255, 0);
        Color red = new Color(0xff, 0x00, 0x00);
        Random rand = new Random();
        Color randcolor = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));

        //颜色对象透明度255 red 0 green 2555 blue 15 alpha 透明度
        //255 不透明 0 完全透明
        Color cc = new Color(255, 0, 255, 15);
        g.setColor(cc);
        g.fillRect(0, 0, w, h);

        Color yy = new Color(255, 0, 0, 255);
        g.setColor(yy);
        //画圆角矩形
        g.drawRoundRect(10, 10, 50, 50, 10, 10);
        g.fillRoundRect(70, 70, 80, 80, 30, 30);


        g.dispose();
        ImageIO.write(i, "png", new File("i.png"));
        Runtime.getRuntime().exec("cmd /k start i.png");
    }
}
